/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.casestudy1.yuh;

import java.io.IOException;
import java.io.InputStream;
import java.util.Vector;
import javax.microedition.io.Connection;
import javax.microedition.io.Connector;
import org.json.me.JSONArray;
import org.json.me.JSONException;
import org.json.me.JSONObject;

/**
 *
 * @author Huy
 */
public class connServer {

    public Vector getAtLocal(final String local) {

        Vector list = new Vector();
        try {
            String url = "http://php.yuh351.asia/trafficinfo/getTrafficInfo.php?local=" + local;
            Connection conn = Connector.open(url);
            InputStream br = Connector.openInputStream(url);

            int c;
            String res = "";

            while ((c = br.read()) != -1) {
                res += (char) c;
            }
            if (res.equals("null")) {
            }
            
            JSONObject jobj = new JSONObject(res);
            
            JSONArray tweets = jobj.getJSONArray("trafficReport");
            JSONObject js;
            
            for (int i = 0; i < tweets.length(); i++) {
                js = tweets.getJSONObject(i);
                trafficReport tr = new trafficReport();
                tr.setId(js.getInt("id"));
                tr.setVitri(js.getString("vitri"));
                tr.setKhuvuc(js.getString("khuvuc"));
                tr.setMucdo(js.getString("mucdo"));
                tr.setNgnhan(js.getString("ngnhan"));
                tr.setTtrang(js.getString("ttrang"));
                list.addElement(tr);
            }
            return list;
        } catch (JSONException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return list;
    }
}
